package com.vincent.kdp.Activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.vincent.kdp.R;
import com.vincent.kdp.js.QualityOperator;
import com.vincent.kdp.ui.other.MainActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/5/12 0012.
 */

public class QualitypolicyActivity extends AppCompatActivity {
    @Bind(R.id.back_img)
    ImageView mBackImg;
    @Bind(R.id.toolbar_center_tv)
    TextView mToolbarCenterTv;
    @Bind(R.id.webView)
    WebView webView;

    private String barCode;
    private String url;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qqq);
        ButterKnife.bind(this);
        mToolbarCenterTv.setText("质保单");

        getParam(getIntent());
        this.initializeWebView();

    }

    private void getParam(Intent intent){
        this.url=intent.getStringExtra("url");

    }

    @SuppressLint({ "NewApi", "SetJavaScriptEnabled" })
    private void initializeWebView(){
        Log.d("AddConsumeActivity","---barcode-"+barCode+"---yrl-"+url);

        webView.addJavascriptInterface(new QualityOperator(QualitypolicyActivity.this,url),
                "Consume");
        try {
            //String url = "file:///android_asset/LoginJs/login.html";

            WebSettings webSettings = webView.getSettings();
            webSettings.setJavaScriptEnabled(true);
            webSettings.setAllowFileAccess(true);
            webSettings.setAllowFileAccessFromFileURLs(true);
            webSettings.setBuiltInZoomControls(false);
            webSettings.setSupportZoom(false);
            webSettings.setDisplayZoomControls(false);
//            setClient();
            this.webView.loadUrl(url);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @OnClick(R.id.back_img)
    public void onClick() {
       Intent it=new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(it);
        overridePendingTransition(com.vincent.baseapp.R.anim.fragment_left_in, com.vincent.baseapp.R.anim.fragment_right_out);
    }

}
